const Promise = require('bluebird');

var promises = [];
const list = [1, 2, 3, 4, 5];

for (var i = 0; i < list.length; ++i) {
    promises.push(list[i]);
}

Promise.all(promises).then(function() {
    console.log("promise:" + promises);  // promise:1,2,3,4,5
});

// Using Promise.map:
Promise.map(list, function(fileName) {
    // Promise.map awaits for returned promises as well.
    return fs.readFileAsync(fileName);
}).then(function() {
    console.log("done");
});

// // Using Promise.map and async/await:
// await Promise.map(fileNames, function(fileName) {
//   // Promise.map awaits for returned promises as well.
//   return fs.readFileAsync(fileName);
// });
// console.log("done");